home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Sample Code / Snippets / Toolbox / SICN LDEF / mylistdef.c next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  2.8 KB  |  120 lines  |  [TEXT/MPS ]

  1. /*    SICN LDEF
  2.  
  3.     ©1991 Apple Computer, Inc.
  4.     written by Steven Falkenburg 5/23/91
  5.     This LDEF displays small icons to the left of text in a list.
  6.     
  7.     The small icon is stored in the first 16 bytes of each cell.
  8. */
  9.  
  10.  
  11. /* constants for spacing */
  12.  
  13. #define kLeftOffset    2
  14. #define kTopOffset    0
  15. #define kIconSpace    2
  16.  
  17. /* prototypes */
  18.  
  19. void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort);
  20.  
  21. /* main LDEF entry point */
  22.  
  23. pascal void    main(short lMessage,Boolean lSelect,Rect *lRect,Cell lCell,
  24.                 short lDataOffset,short lDataLen,ListHandle lHandle)
  25. {
  26.     FontInfo fontInfo;                        /* font information (ascent/descent/etc) */
  27.     ListPtr listPtr;                        /* pointer to store dereferenced list */
  28.     SignedByte hStateList,hStateCells;        /* state variables for HGetState/SetState */
  29.     Ptr cellData;                            /* points to start of cell data for list */
  30.     Ptr theSICN;                            /* points to SICN to be drawn */
  31.     short leftDraw,topDraw;                    /* left/top offsets from topleft of cell */
  32.     
  33.     #pragma unused (lCell)
  34.     
  35.     /* lock and dereference list mgr handles */
  36.     
  37.     hStateList = HGetState(lHandle);
  38.     HLock(lHandle);
  39.     listPtr = *lHandle;
  40.     hStateList = HGetState(listPtr->cells);
  41.     HLock(listPtr->cells);
  42.     cellData = *(listPtr->cells);
  43.     
  44.     switch (lMessage) {
  45.       case lInitMsg:
  46.           /* we don't need any initialization */
  47.           break;
  48.  
  49.       case lDrawMsg:
  50.         EraseRect(lRect);
  51.         
  52.           if (lDataLen > 0) {
  53.           
  54.               /* determine starting point for drawing */
  55.               
  56.               leftDraw =    lRect->left+listPtr->indent.h+kLeftOffset;
  57.               topDraw =    lRect->top+listPtr->indent.v+kTopOffset;
  58.               
  59.               /* plot SICN (first 32 bytes) */
  60.               
  61.               if (lDataLen > 32) {
  62.                   theSICN = cellData+lDataOffset;
  63.                   DrawSICN(theSICN,leftDraw,topDraw,listPtr->port);
  64.                   lDataOffset += 32;
  65.                   lDataLen -= 32;
  66.               }
  67.               leftDraw += 16+kIconSpace;
  68.               
  69.               /* plot text (offset 32 bytes onward) */
  70.               
  71.             GetFontInfo(&fontInfo);
  72.             MoveTo(leftDraw,topDraw+fontInfo.ascent);
  73.             
  74.             /* set condensed mode if necessary (if the text doesn't fit otherwise) */
  75.             
  76.             TextFace(0);
  77.             if (TextWidth(cellData,lDataOffset,lDataLen) > (lRect->right - leftDraw))
  78.                 TextFace(condense);
  79.  
  80.             DrawText(cellData,lDataOffset,lDataLen);
  81.           }
  82.  
  83.         if (!lSelect)
  84.               break;
  85.         
  86.       case lHiliteMsg:
  87.           /* do hilite color */
  88. #ifdef THINK_C
  89.           BitClr(&HiliteMode,pHiliteBit);
  90. #else
  91.           BitClr((Ptr)HiliteMode,pHiliteBit);
  92. #endif
  93.           InvertRect(lRect);
  94.           break;
  95.  
  96.       case lCloseMsg:
  97.           break;
  98.     }
  99.     
  100.     HSetState(listPtr->cells,hStateCells);
  101.     HSetState(lHandle,hStateList);
  102. }
  103.  
  104.  
  105. /* this procedure draws a small icon using CopyBits */
  106.  
  107. void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort)
  108. {
  109.     BitMap iconMap;
  110.     Rect destRect;
  111.  
  112.     iconMap.baseAddr = theSICN;
  113.     iconMap.rowBytes = 2;
  114.     SetRect(&iconMap.bounds,0,0,16,16);
  115.     SetRect(&destRect,0,0,16,16);
  116.     OffsetRect(&destRect,left,top);
  117.     CopyBits(&iconMap,&drawPort->portBits,&iconMap.bounds,&destRect,
  118.             srcCopy,nil);
  119. }
  120.